//不同类型的任务类型，使用不同的图层
//不同的房屋类型，使用不同的图层
//
define([
    "UtilDir/util",
    "UtilDir/tool",
    "static/app/fwsjcj/taskmanage/censusStatisticsEcharts",
],function(Util,Tool,Echarts) {
    var detailedstatisticsMap;

    var detailedstatisticsQueryAjax;
    var detailedstatisticsDatas = [];
    var detailedstatisticsDataInterval;
///////////////////////////////////////////////////////////////////////////天地图工具箱功能

    var polygondetailedStatisticalTool;//任务区域
    var dStatisticalPolygonPoints = [];
    var dstatisticalPolygon;
    var dstatisticalPoints;
    var dcolors = ["blue", "red", "yellow", "DarkOrage", "Lime", "Teal", "Fuchsia", "Green", "Black", "SpringGreen"];

    var dcitys=[];
    var dnocitys=[];
    var dvillagehouses=[];
    var dvillagePublichouses=[];

    /*
    详查数据集合
    * */
    var fwBrickStructure=[];//砖混结构
    var fwBuildingStructure=[];//土木结构
    var fwFactoryStructure=[];//工业厂房结构
    var fwHighStructure=[];//高层结构
    var fwMulConcreteStructure=[];//多层钢筋混凝土
    var fwStoneStructure=[];//石结构
    var fwWideStructure=[];//空旷结构
    var fwWoodStructure=[];//木结构
    var fwStructures=[];//详查总表


    var dstatisticalDatas = [];//选中的房屋
    var nameswitchStructures=[];
    var nameswitchCensuss=[];

    var sysPath =  getServer() + "/static/app/fwsjcj";
    var detailedStatisticsFormHtml = sysPath + "/taskmanage/views/detailedStatisticsForm.html";

    var getZwController = function(){
        return getServer() + "/fw/taskForm";
    };

//初始化
    function detailedstatisticsInitAll() {
        //初始化天地图及切换地图事件
        detailedstatisticsMap = initTMap(detailedstatisticsMap, 'detailedstatistics-map', "#detailedstatistics");
        if (detailedstatisticsMap != null) {//初始化地图成功
            cleardStatisticalPolygon();
            initdetailedStatisticalMapDisplay();
            //初始化事件
            detailedstatisticsInitEvent();
            //添加浏览器的窗口调整地图页面大小事件
            initdetailedStatisticalDivZindex("#detailedstatistics");
            //禁用浏览器右键菜单
            initTMapContextMenu();
            //获取基本数据
            getDetailedBaseDatas();
            getDetailedStructureDatas();
            //显示图例
            displayLegend();
        } else {
            //地图初始化失败
            initAlert("#detailedstatistics", "地图初始化失败", false);
        }
    }

    function getDetailedBaseDatas() {
        dcitys=[];
        dcitys.length=0;
        dnocitys=[];
        dnocitys.length=0;
        dvillagehouses=[];
        dvillagehouses.length=0;
        dvillagePublichouses=[];
        dvillagePublichouses.length=0;
        getdFWDatas("0");// 城镇住宅
        getdFWDatas("1");// 城镇非住宅
        getdFWDatas("2");// 农村住房
        getdFWDatas("3");// 农村公共建筑
    }

    /*
    普查名称包含详查的
    * */
    function getDetailedStructureDatas() {
        nameswitchStructures=[];
        nameswitchStructures.length=0;
        nameswitchCensuss=[];
        nameswitchCensuss.length=0;
        fwStructures=[];
        fwStructures.length=0;
        fwBrickStructure=[];
        fwBrickStructure.length=0;
        getStructure(0);
        fwBuildingStructure=[];
        fwBuildingStructure.length=0;
        getStructure(1);
        fwFactoryStructure=[];
        fwFactoryStructure.length=0;
        getStructure(2);
        fwHighStructure=[];
        fwHighStructure.length=0;
        getStructure(3);
        fwMulConcreteStructure=[];
        fwMulConcreteStructure.length=0;
        getStructure(4);
        fwStoneStructure=[];
        fwStoneStructure.length=0;
        getStructure(5);
        fwWideStructure=[];
        fwWideStructure.length=0;
        getStructure(6);
        fwWoodStructure=[];
        fwWoodStructure.length=0;
        getStructure(7);
    }

    function getStructure(type) {
        debugger;
        var url=getServer() + "/fw//brick/getall";
        if(type==0){
            url=getServer() + "/fw//brick/getall";
        }else if(type==1){
            url=getServer() + "/fw//building/getall";
        }else if(type==2){
            url=getServer() + "/fw//factory/getall";
        }else if(type==3){
            url=getServer() + "/fw//high/getall";
        }else if(type==4){
            url=getServer() + "/fw//mulConcrete/getall";
        }else if(type==5){
            url=getServer() + "/fw//stone/getall";
        }else if(type==6){
            url=getServer() + "/fw//wide/getall";
        }else if(type==7){
            url=getServer() + "/fw//wood/getall";
        }
        $.ajax({
            url: url,
            type: "get",
            success: function (data) {
                for (var i = 0; i < data.length; i++) {
                    var res = data[i];
                    var structure = new fwsjcjFWImportantInfo(res.id,type, res.buildingName, res.buildingAge,null);
                    if(type==0){
                        fwBrickStructure.push(structure);
                    }else if(type==1){
                        fwBuildingStructure.push(structure);
                    }else if(type==2){
                        fwFactoryStructure.push(structure);
                    }else if(type==3){
                        fwHighStructure.push(structure);
                    }else if(type==4){
                        fwMulConcreteStructure.push(structure);
                    }else if(type==5){
                        fwStoneStructure.push(structure);
                    }else if(type==6){
                        fwWideStructure.push(structure);
                    }else if(type==7){
                        fwWoodStructure.push(structure);
                    }
                    fwStructures.push(structure);
                }
            }
        });
    }

    var getdFWDatas = function(type){
        $.ajax({
            url: getZwController() + "/findByType",
            data: {
                type: type
            },
            type: "get",
            success: function (data) {
                for (var i = 0; i < data.length; i++) {
                    var res = data[i];
                    if(type=="0") {
                        var city = new fwsjcjFWDetailinfos(res.fwId,type,res.bulidingLongitude,res.bulidingLatitude,res.buildingName,res.buildingTime,
                            res.structureType,res.housePurpose,res.buildingUpNum,res.presonNum,res.nowFortificationIntensity,res.result,res.spType,res.bulidingType);
                        dcitys.push(city);
                    }else if(type=="1"){
                        var nocity = new fwsjcjFWDetailinfos(res.fwId,type,res.bulidingLongitude,res.bulidingLatitude,res.buildingName,res.buildingTime,
                            res.structureType,res.housePurpose,res.buildingUpNum,"无",res.nowFortificationIntensity,res.result,res.spType,res.bulidingType);
                        dnocitys.push(nocity);
                    }else if(type=="2"){
                        var villagehouse = new fwsjcjFWDetailinfos(res.fwId,type,res.bulidingLongitude,res.bulidingLatitude,res.buildingName,res.buildingTime,
                            res.structureType,"无",res.buildingLayerNum,res.presonNum,"无",res.result,res.spType,res.bulidingType);
                        dvillagehouses.push(villagehouse);
                    }else {
                        var villagePublichouse = new fwsjcjFWDetailinfos(res.fwId,type,res.bulidingLongitude,res.bulidingLatitude,res.buildingName,res.buildingTime,
                            res.structureType,res.housePurpose,res.buildingUpNum,res.presonNum,res.nowFortificationIntensity,res.result,res.spType,res.bulidingType);
                        dvillagePublichouses.push(villagePublichouse);
                    }
                }
            }
        });
    }

    function displayLegend() {
        $("#detailedstatistics-fwlegend").show();
    }

    function initdetailedStatisticalMapDisplay() {
        detailedstatisticsMap.clearOverLays();
    }

//禁用浏览器右键菜单
    function initTMapContextMenu() {
        //禁用浏览器右键菜单
        document.oncontextmenu = function () {
            return false;
        };
    }

//地图缩放到权限位置
    function detailedstatisticsZoomDefaultPosition() {
        cleardStatisticalPolygon();
        //获取权限区域选择列表
        //var LonLat = [113.2, 25.4];
        var LonLat = [103.2, 34.4];
        //地图缩放级别
        var zoom = 4;
        detailedstatisticsMap.centerAndZoom(new TLngLat(LonLat[0], LonLat[1]), zoom);

        //设置主界面图标文字
        initSetZoomDefaultPosition(true, "#detailedstatistics");
    }

    function initSetZoomDefaultPosition(bool, str) {
        if (bool) {//返回主界面
            //设置主界面图标文字
            $(str + "-ZoomDefaultPosition img").attr("src", "/static/app/fwsjcj/taskmanage/image/home-r.png");
            $(str + "-ZoomDefaultPosition span").css("color", "#00a7ff");
        } else {
            //设置主界面图标文字
            $(str + "-ZoomDefaultPosition img").attr("src", "/static/app/fwsjcj/taskmanage/image/home.png");
            $(str + "-ZoomDefaultPosition span").css("color", "#fff");
        }
    }

//初始化DIV层叠顺序，设置Div位置居中
    function initdetailedStatisticalDivZindex(str) {
        if ($(str + "-mapDiv").offset() != undefined) {//有地图页面信息
            var bodyWidth = window.innerWidth - 15;//1920px
            var mapTop = $(str + "-mapDiv").offset().top;//142px
            var mapHeight = window.innerHeight - 40;//796px
            var mapWidth = bodyWidth;//1469px
            //设置地图宽度
            $(str + "-mapDiv").css("width", mapWidth + "px");
            //设置地图高度
            $(str + "-mapDiv").css("height", mapHeight + "px");
            //设置地图宽度
            $(str + "-map").css("width", mapWidth + "px");
            //设置地图高度
            $(str + "-map").css("height", mapHeight + "px");

            //设置鼠标经纬度位置Div位置
            $(str + "-mousemoveLngLatDiv").css("top", mapHeight - 50 + "px");

            //设置左侧控件栏位置
            $(str + "-setDivPosition").css("z-index", "1");

            //消息弹窗
            $(str + "-infosDiv").css("z-index", "3");
            $(str + "-stopQueryDiv").css("z-index", "3");
            //设置消息窗的位置向上居中
            $(str + "-infosDiv").css("left", mapWidth / 2 - $(str + "-infosDiv").outerWidth() / 2 + "px");
            $(str + "-infosDiv").css("top", "100px");
            //设置查询消息框的位置向上居中
            $(str + "-stopQueryDiv").css("left", mapWidth / 2 - $(str + "-stopQueryDiv").outerWidth() / 2 + "px");
            $(str + "-stopQueryDiv").css("top", "100px");

            //右键菜单
            $(str + "-contextMenuDiv").css("z-index", "4");
            //隐藏右键菜单
            $(str + "-contextMenuDiv").hide();
            detailedstatisticsMap.checkResize();
        }
    }

//设置DIV层叠顺序为最大，设置Div位置居中
    function initSetDivZindexMax(id) {
        var strArray = id.split("-");
        if (strArray.length == 2) {
            var str = strArray[0];
            //初始化DIV层叠顺序，设置Div位置居中
            initdetailedStatisticalDivZindex(str);
            //设置DIV的层叠顺序为最大
            $(id).css("z-index", "100");
        }
    }

////////////////////////////////////////////////////////////////////////////////定位工具
//获取鼠标经纬度
    function detailedstatisticsMousePositionCenter() {
        var str = "#detailedstatistics";
        //获取鼠标经纬度——设置图标样式
        initMousePositionCenter(str);
        //鼠标经纬度
        var lng = $(str + "-MousePositionLon").val();
        var lat = $(str + "-MousePositionLat").val();
        if (lng != "" && lat != "") {
            //地图居中到定位图标位置
            detailedstatisticsMap.setCenter(new TLngLat(lng, lat));
            //定位图标
            var icon = new TIcon("/static/app/fwsjcj/taskmanage/image/marker2.png", new TSize(19, 27), {anchor: new TPixel(9, 27)});
            var marker = new TMarker(new TLngLat(lng, lat), {icon: icon});
            //图标文字
            var title = "经度：" + lng + "，纬度：" + lat;
            marker.setTitle(title);
            //添加定位图标到地图叠加层
            detailedstatisticsMap.addOverLay(marker);
            //添加到定位图标数组中
            detailedstatisticsPositionMarkers.push(marker);
            //注册标注点的点击事件
            TEvent.bind(marker, "click", marker, function () {
                var lnglat = this.getLngLat();
                //获取经纬度
                var fmapLonLat = new FMapLonLat({lnglat: lnglat});
                var lonlat = fmapLonLat.getLonLatByLngLat();
                //根据经纬度获取省市边界线
                detailedstatisticsLonLatGetRegion(lonlat);
                //地图居中缩放
                detailedstatisticsSetCenterZoom(lonlat, 18);
            });

        } else {
        }
    }

//获取鼠标经纬度——设置图标样式
    function initMousePositionCenter(str) {
        $(str + "-MousePositionDiv span").css("color", "#fff");
        $(str + "-dw_tj span").css("color", "#00a7ff");
        $(str + "-dw_tj img").attr("src", "/static/app/fwsjcj/taskmanage/image/dingwd-r.png");
        $(str + "-dw_qk img").attr("src", "/static/app/fwsjcj/taskmanage/image/qux.png");
    }


    function detailedstatisticsInitEvent() {
        //天地图事件
        $("#detailedstatistics-ZoomDefaultPosition").unbind("click");
        $("#detailedstatistics-ZoomDefaultPosition").click(function () {
            detailedstatisticsZoomDefaultPosition();
        });
        $("#detailedstatisticalanalysisDiv").unbind("click");
        $("#detailedstatisticalanalysisDiv").click(function () {
            creatDetailedRegion();
        });

        detailedstatisticsTMapEvent();
    }

    function cleardStatisticalPolygon() {
        $("#detailedstatistics-contextMenuDiv").hide();
        if (dstatisticalPolygon != null) {
            detailedstatisticsMap.removeOverLay(dstatisticalPolygon);
        }
        if (polygondetailedStatisticalTool != null) {
            polygondetailedStatisticalTool.clear();
            polygondetailedStatisticalTool.close();
        }
    }

    function creatDetailedRegion() {
        cleardStatisticalPolygon();
        if ($("#detailedstatisticalanalysisDiv img").attr("title") == "详查统计") {
            $("#detailedstatisticalanalysisDiv img").attr("title", "取消统计");
            $("#detailedstatisticalanalysisDiv").children("span").html("取消统计");
            var index = Math.floor(Math.random() * 10);
            var color = dcolors[index];
            var config = {
                strokeColor: color, //折线颜色
                fillColor: "#FFFFFF",    //填充颜色。当参数为空时，折线覆盖物将没有填充效果
                strokeWeight: "3px", //折线的宽度，以像素为单位
                strokeOpacity: 1,  //折线的透明度，取值范围0 - 1
                fillOpacity: 0.2,        //填充的透明度，取值范围0 - 1
                showLabel: false             //是否显示页面，默认为true.
            };
            //创建任务工具对象
            polygondetailedStatisticalTool = new TPolygonTool(detailedstatisticsMap, config);
            polygondetailedStatisticalTool.setTips("单击鼠标左键绘制圈选区域点，双击完成绘制圈选区域");
            //注册测面工具绘制完成后的事件
            TEvent.addListener(polygondetailedStatisticalTool, "draw", onDrawHZPolygon);
            polygondetailedStatisticalTool.open();

            //添加多边形
            function onDrawHZPolygon(bounds, line) {
                dStatisticalPolygonPoints.length = 0;
                polygondetailedStatisticalTool.clear();
                dstatisticalPolygon = new TPolygon(bounds, {
                    strokeColor: "red",
                    strokeWeight: 3,
                    strokeOpacity: 1,
                    fillOpacity: 0.2
                });
                detailedstatisticsMap.addOverLay(dstatisticalPolygon);//添加多边形

                var points = lnglatdataswitch(dstatisticalPolygon.getLngLats());
                dstatisticalPoints=points;
                polygondetailedStatisticalTool.close();

                dstatisticalDatas=[];
                dstatisticalDatas.length=0;

                nameswitchStructures=[];
                nameswitchStructures.length=0;
                nameswitchCensuss=[];
                nameswitchCensuss.length=0;

                for (var i = 0; i < dcitys.length; i++) {
                    var info = dcitys[i];
                    if(initPointInsidePolygon(points,info.point)) {
                        dstatisticalDatas.push(info);
                    }
                }
                for (var i = 0; i < dnocitys.length; i++) {
                    var info = dnocitys[i];
                    if(initPointInsidePolygon(points,info.point)) {
                        dstatisticalDatas.push(info);
                    }
                }
                for (var i = 0; i < dvillagehouses.length; i++) {
                    var info = dvillagehouses[i];
                    if(initPointInsidePolygon(points,info.point)) {
                        dstatisticalDatas.push(info);
                    }
                }
                for (var i = 0; i < dvillagePublichouses.length; i++) {
                    var info = dvillagePublichouses[i];
                    if(initPointInsidePolygon(points,info.point)) {
                        dstatisticalDatas.push(info);
                    }
                }

                for(var i=0;i<fwStructures.length;i++){
                    var data1=fwStructures[i];
                    for(var j=0;j<dstatisticalDatas.length;j++){
                        var data2=dstatisticalDatas[j];
                        if(data2.name!=null&&data2.name!=""&&data1.name!=null&&data1.name!=""&&data2.name.indexOf(data1.name)!=-1){
                            debugger;
                            nameswitchStructures.push(data1);
                            continue;
                        }
                    }
                }
                for(var i=0;i<dstatisticalDatas.length;i++){
                    var data1=dstatisticalDatas[i];
                    for(var j=0;j<fwStructures.length;j++){
                        var data2=fwStructures[j];
                        if(data2.name!=null&&data2.name!=""&&data1.name!=null&&data1.name!=""&&data1.name.indexOf(data2.name)!=-1){
                            nameswitchCensuss.push(data1);
                            continue;
                        }
                    }
                }

                for (var i = 0; i < nameswitchCensuss.length; i++) {
                    var info = nameswitchCensuss[i];
                    var icon = initTMapGetIconByType(info.buildtype, info.sptype);
                    initTMapAddMarkLabelArray(detailedstatisticsMap, info, info.point, info.name, icon);
                }
            }
        }else{
            $("#detailedstatisticalanalysisDiv img").attr("title", "详查统计");
            $("#detailedstatisticalanalysisDiv").children("span").html("详查统计");
            detailedstatisticsMap.clearOverLays();
        }
    }

//天地图事件
    function detailedstatisticsTMapEvent() {
        //地图事件
        detailedstatisticsMap = initTMapEvent("#detailedstatistics", detailedstatisticsMap);

        //地图鼠标点击事件
        TEvent.addListener(detailedstatisticsMap, "click", function (p, btn) {
            //将像素坐标转换成经纬度坐标
            var lnglat = detailedstatisticsMap.fromContainerPixelToLngLat(p);
            var Lon = lnglat.getLng();
            var Lat = lnglat.getLat();
            $("#detailedstatistics-contextMenuDiv").hide();
            if (btn == 1) {//鼠标左键
                //获取鼠标位置的经纬度
                $("#detailedstatistics-MousePositionLon").val(Lon);
                $("#detailedstatistics-MousePositionLat").val(Lat);
            } else if (btn == 2) {
                var hitPoint = [];
                hitPoint[0] = Lon;
                hitPoint[1] = Lat;
                if (dstatisticalPoints != null && dstatisticalPoints.length > 2) {
                    if (initPointInsidePolygon(dstatisticalPoints, hitPoint)) {
                        initShowContextMenu("#detailedstatistics", 1, p[0], p[1]);
                        dstatisticalCreateContextMenu();
                        return;
                    }
                }
            }
        });
    }

    function dstatisticalCreateContextMenu() {
        //设置右键菜单点击事件
        $("#detailedstatistics-ContextMenuLi").off("click");
        $("#detailedstatistics-ContextMenuLi").on("click", function () {
            if (dstatisticalDatas != null && dstatisticalDatas.length > 0) {
                $("#detailedstatistics-contextMenuDiv").hide();
                if(nameswitchCensuss!=null&&nameswitchCensuss.length>0){
                    _viewDetailedStatisticsInfo();
                }else{
                    Util.alert("所选区域房屋信息没有对应的详查数据。");
                }
                //_viewCensusStatisticsInfo(dstatisticalDatas);
            }else{
                $("#detailedstatistics-contextMenuDiv").hide();
                Util.alert("所选区域没有房屋数据。");
            }

        });
    }

    window._viewDetailedStatisticsInfo = function() {
        var slidebar = Util.slidebar({
            url: detailedStatisticsFormHtml,
            width: "450px",
            cache: false,
            close : true,

            afterOpen: function () {
                selectDetailedRadio();
                $("#circledetailedfwNum").val(nameswitchStructures.length);
                $('.nav-map.nav-tabs').hide();
            },
            afterLoad: function () {
                $("#dr1").on("click", function () {
                    selectDetailedRadio();
                });
                $("#dr2").on("click", function () {
                    selectDetailedRadio();
                });
                $("#dr3").on("click", function () {
                    selectDetailedRadio();
                });

            }
        });
    };

    function hideUnusedDiv(){
        $("#detailedmapbuildingTypeState").hide();
        $("#detailedmapmapageBuildTimeState").hide();
        $("#detailedmapearthquakeState").hide();
    }

    window.selectDetailedRadio = function() {
        var rd=document.getElementsByName('rdDetailedStatistics');
        hideUnusedDiv();
        if(rd[0].checked)
        {
            $("#detailedmapbuildingTypeState").show();
            createDetailedBuildTypeEcharts();
            document.getElementById("detailedmapbuildingTypelab").click();
        }
        if(rd[1].checked)
        {
            $("#detailedmapmapageBuildTimeState").show();
            createDetailedAgeBuildEcharts();
            document.getElementById("detailedmapmapageBuildTimelab").click();
        }
        if(rd[2].checked)
        {
            $("#detailedmapearthquakeState").show();
            createDetailedNowfortificationintensityEcharts();
            document.getElementById("detailedmapearthquakelab").click();
        }

    }

    var createDetailedNowfortificationintensityEcharts = function(){
        Echarts.createPieEcharts({
            id:"detailedmapearthquake",
            legenddata: ['0（不设防）','6（VI度设防）','7（VII度设防）','8（VIII度设防）','9（IX度设防）'],
            title: "现抗震设防烈度",
            subtitle: '栋数',
            series: [
                {
                    name: '栋数',
                    data: [
                        {value: getDetailedNowfortificationintensityNum("未设防"), name: '0（不设防）'},
                        {value: getDetailedNowfortificationintensityNum("6"), name: '6（VI度设防）'},
                        {value: getDetailedNowfortificationintensityNum("7"), name: '7（VII度设防）'},
                        {value: getDetailedNowfortificationintensityNum("8"), name: '8（VIII度设防）'},
                        {value: getDetailedNowfortificationintensityNum("9"), name: '9（IX度设防）'}
                    ]
                }
            ]
        });
        Echarts.resizeEcharts('detailedmapearthquake');
    }

    function getDetailedNowfortificationintensityNum(type) {
        var num=0;
        for(var i=0;i<nameswitchCensuss.length;i++){
            var data = nameswitchCensuss[i];
            if(data.nowfortificationintensity!=null&&data.nowfortificationintensity!=""&&data.nowfortificationintensity.indexOf(type)!=-1){
                num++;
            }
        }
        return num;
    }

    var createDetailedBuildTypeEcharts = function(){
        Echarts.createPieEcharts({
            id:"detailedmapbuildingType",
            legenddata: ['砖混结构','土木结构','工业厂房结构','高层结构','多层钢筋混凝土','石结构','空旷结构','木结构'],
            title: "建筑物类型",
            subtitle: '栋数',
            series: [
                {
                    name: '栋数',
                    data: [
                        {value: getDetailedFWBuildTypeNum("0"), name: '砖混结构'},
                        {value: getDetailedFWBuildTypeNum("1"), name: '土木结构'},
                        {value: getDetailedFWBuildTypeNum("2"), name: '工业厂房结构'},
                        {value: getDetailedFWBuildTypeNum("3"), name: '高层结构'},
                        {value: getDetailedFWBuildTypeNum("4"), name: '多层钢筋混凝土'},
                        {value: getDetailedFWBuildTypeNum("5"), name: '石结构'},
                        {value: getDetailedFWBuildTypeNum("6"), name: '空旷结构'},
                        {value: getDetailedFWBuildTypeNum("7"), name: '木结构'}
                    ]
                }
            ]
        });
        Echarts.resizeEcharts('detailedmapbuildingType');
    }

    function getDetailedFWBuildTypeNum(type) {
        var num=0;
        for(var i=0;i<nameswitchStructures.length;i++){
            var data = nameswitchStructures[i];
            if(data.type==type){
                num++;
            }
        }
        return num;
    }

    var createDetailedAgeBuildEcharts = function(){
        Echarts.createPieEcharts({
            id:"detailedmapmapageBuildTime",
            legenddata: ['70s以前','70s','80s','90s','00s','10s'],
            title: "年代",
            subtitle: '栋数',
            series: [
                {
                    name: '栋数',
                    data: [
                        {value: getDetailedFWAgeNum("70s以前"), name: '70s以前'},
                        {value: getDetailedFWAgeNum("70s"), name: '70s'},
                        {value: getDetailedFWAgeNum("80s"), name: '80s'},
                        {value: getDetailedFWAgeNum("90s"), name: '90s'},
                        {value: getDetailedFWAgeNum("00s"), name: '00s'},
                        {value: getDetailedFWAgeNum("10s"), name: '10s'}
                    ]
                }
            ]
        });
        Echarts.resizeEcharts('detailedmapmapageBuildTime');
    }

    function getDetailedFWAgeNum(years) {
        var num=0;
        for(var i=0;i<nameswitchCensuss.length;i++){
            var data = nameswitchCensuss[i];
            if(data.buildingtime==years){
                num++;
            }
        }
        return num;
    }

    function initTMapEvent(str, map) {
        //str:#statistical-analysis
        if (map != null) {
            //地图当前鼠标位置
            //注册鼠标在地图上的滑动事件
            TEvent.addListener(map, "mousemove", function (p) {
                //将像素坐标转换成经纬度坐标
                var lnglat = map.fromContainerPixelToLngLat(p);
                $(str + "-mousemoveLngLatDiv").html("鼠标位置经纬度：" + lnglat.getLng() + "," + lnglat.getLat());
            });
            //地图拖拽事件
            TEvent.addListener(map, "mousedrag", function () {
                //设置主界面图标文字
                initSetZoomDefaultPosition(false, str);
                $(str + "-contextMenuDiv").hide();
            });

            //地图缩放事件
            TEvent.addListener(map, "zoom", function () {
                //设置主界面图标文字
                initSetZoomDefaultPosition(false, str);
                var zoom = map.getZoom();
                if (str == "#detailedstatistics") {

                    if (zoom > 4) {
                    } else if (zoom == 4) {
                        //地图缩放到权限位置
                        //detailedstatisticsZoomDefaultPosition();
                    }

                }

            });
        }

        return map;
    }

    function initSetSwitchMap(str, map) {
        cleardStatisticalPolygon();
        var strSwitchMap = str + "-switchMap";
        $(strSwitchMap).children("span").html("卫星图");
        $(strSwitchMap).children("img").attr("title", "切换卫星地图");
        $(strSwitchMap).children("img").attr("src", "/static/app/fwsjcj/taskmanage/image/weixing-b.png");
        $(strSwitchMap).children("img").css("margin-left", "5px");
        //显示街道图
        map.setMapType(TMAP_NORMAL_MAP);
        //切换卫星图和街道图事件
        $(strSwitchMap).click(function () {
            //切换地图功能控件
            if ($(strSwitchMap).children("img").attr("src") == "/static/app/fwsjcj/taskmanage/image/jiedao-b.png") {
                $(strSwitchMap).children("span").html("卫星图");
                $(strSwitchMap).children("img").attr("title", "切换卫星地图");
                $(strSwitchMap).children("img").attr("src", "/static/app/fwsjcj/taskmanage/image/weixing-b.png");
                $(strSwitchMap).children("img").css("margin-left", "5px");
                //显示街道图
                map.setMapType(TMAP_NORMAL_MAP);
            } else if ($(strSwitchMap).children("img").attr("src") == "/static/app/fwsjcj/taskmanage/image/weixing-b.png") {
                $(strSwitchMap).children("span").html("街道图");
                $(strSwitchMap).children("img").attr("title", "切换街道地图");
                $(strSwitchMap).children("img").attr("src", "/static/app/fwsjcj/taskmanage/image/jiedao-b.png");
                //显示卫星图
                map.setMapType(TMAP_HYBRID_MAP);//卫星图（有标注）
            }
        });
    }

//初始化卫星和街道地图及切换地图事件
    function initTMap(map, strMap, str) {
        try {
            //判断是否连接上地图API
            var temp = TLocalSearch();
            var config = {
                projection: "EPSG:4326"
            }
            //初始化地图对象
            map=new TMap(strMap,config);
            //初始化地图
            //map = new TMap(strMap);
            //清空地图
            map.clearOverLays();
            //地图中心坐标--全国
            //var LonLat  = [109.2, 34.4];
            //var LonLat = [113.2, 25.4];
            var LonLat = [103.2, 34.4];
            //地图缩放级别
            var zoom = 4;
            map.centerAndZoom(new TLngLat(LonLat[0], LonLat[1]), zoom);
            map.enableDoubleClickZoom();
            map.enableHandleMouseScroll();

            //创建比例尺控件对象
            var scale = new TScaleControl();
            //添加比例尺控件
            map.addControl(scale);

            //鹰眼
            var configOverView = {
                anchor: "TMAP_ANCHOR_BOTTOM_RIGHT",	//设置鹰眼位置,"TMAP_ANCHOR_TOP_LEFT"表示左上，"TMAP_ANCHOR_TOP_RIGHT"表示右上，"TMAP_ANCHOR_BOTTOM_LEFT"表示左下，"TMAP_ANCHOR_BOTTOM_RIGHT"表示右下，"TMAP_ANCHOR_LEFT"表示左边，"TMAP_ANCHOR_TOP"表示上边，"TMAP_ANCHOR_RIGHT"表示右边，"TMAP_ANCHOR_BOTTOM"表示下边，"TMAP_ANCHOR_OFFSET"表示自定义位置,默认值为"TMAP_ANCHOR_BOTTOM_RIGHT"
                size: new TSize(180, 120),			//鹰眼显示的大小
                isOpen: true						//鹰眼是否打开，true表示打开，false表示关闭，默认为关闭
            };
            //创建鹰眼控件对象
            var overviewMap = new TOverviewMapControl(configOverView);
            //添加鹰眼控件
            map.addControl(overviewMap);

            //地图缩放平移控件
            var config = {
                type: "TMAP_NAVIGATION_CONTROL_ZOOM",	//缩放平移的显示类型
                anchor: "TMAP_ANCHOR_TOP_RIGHT",			//缩放平移控件显示的位置
                offset: [0, 0],							//缩放平移控件的偏移值
                showZoomInfo: false						//是否显示级别提示信息，true表示显示，false表示隐藏。
            };
            //创建缩放平移控件对象
            var navigationControl = new TNavigationControl(config);
            //添加缩放平移控件
            map.addControl(navigationControl);

            //设置地图显示级别
            map.setZoomLevels([4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18]);

            //切换卫星和街道图
            initSetSwitchMap(str, map);
            //设置控件显示
            $(str + "-setDivPosition").show();//显示工具条控件
            $(str + "-mousemoveLngLatDiv").show();//显示鼠标经纬度信息栏
            $(str + "-tabControlDiv").show();//显示侧边栏

            //全屏设置功能
            //initTMapSetFullScreen();

        } catch (e) {
            map = null;
        }

        return map;
    }

//信息窗样式设置
    function initAlert(str, data, bool) {
        if (data == "没有选择区域" || data == "初始化成功！" || data == "初始化失败！" || data == "地图初始化失败！" || data == "查询成功！" || data == "查询失败！" || data == "无查询结果！" || data == "处理成功！" || data == "处理失败！" || data == "设置成功！" || data == "设置失败！" || data == "保存成功！" || data == "删除成功！" || data == "清空成功！" || data == "线路规划成功！") {
            $(str + "-stopQueryDiv").hide();
        }
        //设置DIV层叠顺序为最大
        initSetDivZindexMax(str + "-infosDiv");
        //消息提示图标
        if (bool) {//成功
            $(str + "-infosDiv img").attr("src", "/static/app/fwsjcj/taskmanage/image/succes.png");
        } else {//失败
            $(str + "-infosDiv img").attr("src", "/static/app/fwsjcj/taskmanage/image/error.png");
        }
        $(str + "-infosDiv img").css("top", "75px");
        $(str + "-infosDiv img").css("left", "60px");
        //设置信息框显示文字
        $(str + "-infosDiv p").html(data);
        $(str + "-infosDiv").show();
        //消息提示3秒后自动关闭
        setTimeout(function () {
            $(str + "-infosDiv").hide();
        }, 1000);
    }

    return {
        detailedstatisticsInitAll: detailedstatisticsInitAll
    };
});